<script>
import axios from "axios";
var layerBox = [],
  maps = {};
var addressUrl = "", //http://115.233.209.175//Geocoding/LiquidGIS/FindAddress.gis
  layerTypeTreeUrl = "", //"http://115.233.209.175:8090/zh-CN/map/LayerCatalog/GetTreeList?id=0",
  attachUrl = "", //http://115.233.209.175:8090
  historyLayer = "",
  loginUrl="",
  layerData = ""; //GetLayermetadata
  var mapWkid=4490;
  var mapZoom=11;
  var x="";
  var y="";
  var themeColor="b";

function addconfig() {
  var data = {};
  var p = new Promise(function(resolve, reject) {
    axios.get("/static/Data/config.xml").then(function(response) {
      // handle success
      //console.log(response);
      var configXml = string2XML(response.data);
      console.log(configXml);
      data.layerTypeTreeUrl = configXml
        .getElementsByTagName("layerTypeTreeUrl")[0]
        .getAttribute("url");
      data.attachUrl = configXml
        .getElementsByTagName("attachUrl")[0]
        .getAttribute("url");
      data.historyLayer = configXml
        .getElementsByTagName("historyLayer")[0]
        .getAttribute("url");
      data.layerData = configXml
        .getElementsByTagName("layerData")[0]
        .getAttribute("url");
      data.addressUrl = configXml
        .getElementsByTagName("addressUrl")[0]
        .getAttribute("url");
      data.loginUrl = configXml
        .getElementsByTagName("loginUrl")[0]
        .getAttribute("url");
        data.mapWkid = configXml
        .getElementsByTagName("map")[0]
        .getAttribute("wkid");
        data.mapZoom = configXml
        .getElementsByTagName("map")[0]
        .getAttribute("zoom");
            data.x = configXml
        .getElementsByTagName("map")[0]
        .getAttribute("x");
            data.y = configXml
        .getElementsByTagName("map")[0]
        .getAttribute("y");
        data.themeColor = configXml
        .getElementsByTagName("style")[0]
        .getAttribute("color");

        
        
      resolve(data);
    });
  });
  return p;
}

function runAsync(tagName, attr) {
  var p = new Promise(function(resolve, reject) {
    //做一些异步操作
    axios.get("/static/Data/config.xml").then(function(response) {
      var configXml = string2XML(response.data);
      console.log(configXml);

      var data = configXml.getElementsByTagName(tagName)[0].getAttribute(attr);
      resolve(data);
    });
    // setTimeout(function(){
    //    console.log('执行完成');
    //    resolve('随便什么数据');
    // }, 2000);
  });
  return p;
}

/* runAsync("layerTypeTreeUrl","url").then(function(data){

}) */

function string2XML(xmlString) {
  //所有浏览器统一用这种方式处理(因为高版本的浏览器都支持)
  var parser = new DOMParser();
  var xmlObject = parser.parseFromString(xmlString, "text/xml");
  return xmlObject;
}
Array.prototype.contains = function(obj) {
  var i = this.length;
  while (i--) {
    if (this[i] === obj || this[i] === obj.toString()) {
      return true;
    }
  }
  return false;
};
Array.prototype.remove = function(obj) {
  var i = this.length;
  while (i--) {
    if (this[i] === obj || this[i] === obj.toString()) {
      this.splice(index, 1);
      return true;
    }
  }
  return false;
};
/* exports.addconfig = function (Vue, options) {

}; */
//addconfig();
export default {
  runAsync,
  addconfig,
  layerBox,
  maps,
  addressUrl,
  layerTypeTreeUrl,
  loginUrl,
  attachUrl,
  mapWkid,
  mapZoom,
  themeColor,x,y
};
</script>
